package cn.doit.day04

object _01_不可变数组 {
  def main(args: Array[String]): Unit = {
    //    val ints: Array[Int] = new Array[Int](10)
    //算子==》 mkString
    //    println(ints.mkString("_"))

    //增删改查
    val ints1: Array[Int] = Array(1,1,1,1,1,2,3,4,5,6,7)

    val ints6: Array[Int] = ints1.drop(2)
//    println(ints6.mkString(",")) //3,4,5,6,7

//    val fun = (a:Int)=>{a % 2 == 1}//如果是true 我就留着，如果是false就删除掉

    val ints7: Array[Int] = ints1.dropWhile((a:Int)=>{a % 2 == 1})//从左到右去判断
    val res7: String = ints7.mkString(",")//全部留的奇数，要么全部留的偶数
    println(res7)//1,2,3,4,5,6,7   2,3,4,5,6,7


    //    ints1.sum
    //    ints1.max
    //    ints1.min
    val ints2: Array[Int] = Array(4, 5, 6, 7, 8, 9)

    val ints3: Array[Int] = ints1.intersect(ints2) //交集   4567
    val ints4: Array[Int] = ints1.diff(ints2) //差集 123
    val ints5: Array[Int] = ints1.union(ints2) //并集
    println(ints3.mkString(","))
    println(ints4.mkString(","))
    println(ints5.mkString(",")) //1,2,3,4,5,6,7,4,5,6,7,8,9


    val last: Int = ints1.last //获取数组中最后一个元素
    println(last) //7

    val head: Int = ints1.head //获取数组中第一个元素
    println(head) //1

    val tail: Array[Int] = ints1.tail //获取除了第一个的剩下的所有的元素组成的集合
    println(tail.mkString(",")) //234567


    val ints: Array[Int] = ints1.take(2) //从左到右，获取2个元素
    println(ints.mkString(",")) //12


    println(ints1.mkString(","))

    /*    ints1.update(0,100)

        val i: Int = ints1.apply(0)//arr[0]
        val i1: Int = ints1(0)//arr[0]
        println(i1)*/

    //+:   将元素添加到原来数组的最前面，并且返回新的数组给你
    val res: Array[Int] = ints1.+:(10)
    println(res.mkString(",")) //10,1,2,3,4,5,6,7

    println(ints1.mkString(","))

    //:+   将元素添加到原来数组的最后面，并且返回新的数组给你
    val res1: Array[Int] = ints1.:+(10)
    println(res1.mkString(",")) //1,2,3,4,5,6,7,10


//    val a: Array[Int] = Array(1, 2, 3)
//    val b: Array[Int] = Array(4, 5, 6)

    //传一个数组或者传一个集合
    /*    val res2: Array[Int] = a.++(b)
        val res3: Array[Int] = a.++:(b)
        println(res2.mkString(","))//1,2,3,4,5,6
        println(res3.mkString(","))//4,5,6,1,2,3*/


  }

}
